print('='*30,'第一章作业3','='*30)
print()

import os

usr_data = [
    {'ID': 'user1', 'password':'1', 'money': 1000},
    {'ID': 'user2', 'password':'2', 'money': 1000},
    {'ID': 'user3', 'password':'3', 'money': 1000}]
#银行取款机界面
def printMenu():
    print("=" * 30,'自动取款机',"=" * 30)
    print("请先登录")

#银行登录系统
def ATM_Login():
    global ATMUser
    global flag_login
    flag_login= True
    ID = input("请您的输入账号：")
    password = input("请您的输入密码：")
    for v in range(len(usr_data)):
        if usr_data[v]["ID"] == ID and usr_data[v]['password'] == password: #判断账号密码是否正确
            ATMUser = ID # 记录操作用户id
            print("登陆成功，请继续操作！")
            flag_login = True
            break
        else:
            if input("输入的账号密码有误，是否重新输入 yes/no?  ") == "yes":
                ATM_Login() # 重新输入
                break
#银行余额查询系统
def ATM_Show():
    for v in range(len(usr_data)):
        if usr_data[v]["ID"] == ATMUser: #判断是否为登录账号
            print('姓名:', ATMUser, '     ', '余额:',usr_data[v]['money'])
            break
#银行取钱系统
def ATM_DrawMoney():
    for v in range(len(usr_data)):
        if usr_data[v]["ID"] == ATMUser: #判断是否为登录账号
            drawMoney = input("请输入你要取出的金额：")
            if usr_data[v]['money']>int(drawMoney):#判断余额是否充足
                usr_data[v]['money']-=int(drawMoney)
                print("您成功取款{}元".format(drawMoney))
                break
            else:
                print("您的账户余额不足！")
            break

#银行存钱系统
def ATM_SunMoney():
    for v in range(len(usr_data)):
        if usr_data[v]["ID"] == ATMUser: #判断是否为登录账号
            sunMoney = input("请输入你要取出的金额：")
            usr_data[v]['money']+=int(sunMoney)
            print("您成功取款{}元".format(sunMoney))




while True:
    printMenu()
    ATM_Login()
    while flag_login:
        print("1.查询余额")
        print("2.取钱")
        print('3.存钱')
        print("0.退出")
        print("=" * 60)
        key = input("请输入你要选择的操作：")
        if key == '1':
            ATM_Show()
        elif key == '2':
            ATM_DrawMoney()
        elif key == '3':
            ATM_SunMoney()
        elif key == '0':
            flag_login = False
